package com.qf.service.impl;

import com.qf.entity.Questions;
import com.qf.mapper.QuestionsMapper;
import com.qf.service.QuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lenovo
 * @version V1.0
 * @Date 2021/10/6 2:19
 */
@Service
public class QuestionsServiceImpl implements QuestionsService {

    @Autowired
    private QuestionsMapper questionsMapper;

    @Override
    public List<Questions> findAll() {
        return questionsMapper.findAll();
    }

    @Override
    public List<Questions> findAllBytitle(String title) {
        return questionsMapper.findAllBytitle(title);
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void add(Questions questions) {
        int i = questionsMapper.insert(questions);
        if (i != 1){
            System.out.println("添加失败");
            throw new RuntimeException("添加失败");
        }
    }

    @Override
    @Transactional(rollbackFor = Throwable.class)
    public void update(Questions questions) {
        int i = questionsMapper.updateByPrimaryKey(questions);
        if (i != 1){
            System.out.println("修改失败");
            throw new RuntimeException("修改失败");
        }

    }
}
